package com.fresh.controller;

import com.fresh.common.ResponseResult;
import com.fresh.entity.FreshCategory;
import com.fresh.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RefreshScope
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;


    @GetMapping("/all")
    public ResponseResult all(){
        List<FreshCategory> categoryList = categoryService.getAll();
        return ResponseResult.success(categoryList);
    }

    @PostMapping("/updateStatus")
    public ResponseResult updateStatus(@RequestBody FreshCategory category){
        categoryService.updateStatusById(category);
        return ResponseResult.success();
    }

    @GetMapping("/main")
    public ResponseResult main(){
        List<FreshCategory> categoryList = categoryService.getMainCategory();
        return ResponseResult.success(categoryList);
    }

    /**
     * 查询所有子类别
     * @return
     */
    @GetMapping("/deputy")
    public ResponseResult deputy(){
        List<FreshCategory> categoryList = categoryService.getDeputyCategory();
        return ResponseResult.success(categoryList);
    }
}
